﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using ContaSuite.ViewModel;

namespace ContaSuite.View
{
    /// <summary>
    /// Interaction logic for ClientView.xaml
    /// </summary>
    public partial class ClientView : Window
    {
        ClientViewModel _clientViewModel;
        public ClientView()
        {
            InitializeComponent();
            _clientViewModel = new ClientViewModel();
            this.DataContext = _clientViewModel;
        }

        private void txt_search_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (txt_search.Text != "")
            {
                _clientViewModel.SetClientList(txt_search.Text);

                if (_clientViewModel.ClientList.Count() > 0)
                {
                    dg_search.ItemsSource = _clientViewModel.ClientList;
                    dg_search.Visibility = Visibility.Visible;

                }
                else
                {
                    dg_search.Visibility = Visibility.Hidden;
                }
            }
            else
            {
                dg_search.Visibility = Visibility.Hidden;
            }



            

        }

        private void dg_search_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            _clientViewModel.SelectedClient=(x_client) dg_search.SelectedItem;

            //MessageBox.Show("ssrgsrgrgs");
        }

        private void dg_search_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            dg_search.Visibility = Visibility.Hidden;
        }

        private void txt_search_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Down)
            {
                MessageBox.Show(e.Key.ToString());
            }
        }
    }
}
